package demo1;

import java.util.HashMap;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    //最长定差子序列
    public int longestSubsequence(int[] arr, int difference) {
        int max = 1;
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        for(int i=0;i<arr.length;i++){
            Integer val = map.get(arr[i] - difference);
            if(val != null){
                map.put(arr[i],val+1);
                max = max >= val+1 ? max : val+1;
            }
            else
                map.put(arr[i],1);
        }
        return max;
    }
}
